package com.carleasoft.mps.cms.business.write.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.resource.bean.vo.WebCountVo;
import com.carleasoft.mps.cms.business.write.bean.entity.LeadingCadreEntity;
import com.carleasoft.mps.cms.business.write.bean.entity.LeadingViewEntity;
import com.carleasoft.mps.cms.business.write.bean.po.AppointPo;
import com.carleasoft.mps.cms.business.write.bean.po.LeadingCadrePagePo;
import com.carleasoft.mps.cms.business.write.bean.vo.LeadingCountVo;
import com.carleasoft.mps.cms.business.write.bean.vo.UpAndDownVo;
import com.carleasoft.mps.cms.business.write.service.LeadingAppointService;
import com.carleasoft.mps.cms.business.write.service.LeadingCadreService;
import com.carleasoft.mps.cms.business.write.service.LeadingViewService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * 给首长/科室的信
 *
 * @author: yangHao
 * @createDate:2023/6/7
 * @description:
 */
@RestController
@RequestMapping("/leading")
public class LeadingCadreController {
    @Autowired
    private LeadingCadreService leadingCadreService;
    @Autowired
    private LeadingViewService leadingViewService;
    @Autowired
    private LeadingAppointService leadingAppointService;

    /**
     * 添加信箱
     *
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody LeadingCadreEntity leadingCadreEntity, HttpServletRequest request) {
        boolean isOk = leadingCadreService.saveLeading(leadingCadreEntity, request);
        return R.ok(isOk);
    }

    /**
     * 分页
     *
     * @param leadingCadrePagePo
     * @return
     */
    @PostMapping("/pageQuery")
    public R pageQuery(@RequestBody LeadingCadrePagePo leadingCadrePagePo) {
        Page<LeadingCadreEntity> leadingCadreEntityPage = leadingCadreService.pageQuery(new Page(leadingCadrePagePo.getCurrent(), leadingCadrePagePo.getSize()), leadingCadrePagePo);
        return R.ok(leadingCadreEntityPage);
    }

    /**
     * 详情
     *
     * @param leadingCadrePagePo
     * @return
     */
    @PostMapping("/detail")
    public R detail(@RequestBody LeadingCadrePagePo leadingCadrePagePo) {
        IBeanUtil.paramVerify(leadingCadrePagePo, "writeCode");
        LeadingCadreEntity leadingCadreEntity = leadingCadreService.detail(leadingCadrePagePo);
        return R.ok(leadingCadreEntity);
    }

    /**
     * 详情返回成功时 访问量+1
     *
     * @param leadingViewEntity
     * @return
     */
    @PostMapping("/addView")
    public R addView(@RequestBody LeadingViewEntity leadingViewEntity) {
        IBeanUtil.paramVerify(leadingViewEntity, "writeCode");
        boolean isOk = leadingViewService.addView(leadingViewEntity);
        return R.ok(isOk);
    }

    /**
     * 信箱统计
     *
     * @return
     */
    @PostMapping("/leadingCount")
    public R leadingCount() throws ParseException {
        LeadingCountVo leadingCountVo = leadingCadreService.leadingCount();
        return R.ok(leadingCountVo);
    }

    /**
     * 上下篇
     *
     * @param leadingCadreEntity
     * @return
     */
    @PostMapping("/upAndDown")
    public R upAndDown(@RequestBody LeadingCadreEntity leadingCadreEntity) {
        IBeanUtil.paramVerify(leadingCadreEntity, "writeCode");
        UpAndDownVo upAndDownVo = leadingCadreService.upAndDown(leadingCadreEntity.getWriteCode());
        return R.ok(upAndDownVo);
    }


    /**
     * web-信箱概况
     *
     * @return
     */
    @PostMapping("/leadingWebCount")
    public R leadingWebCount() {
        List<WebCountVo> webCountVos = leadingCadreService.leadingWebCount();
        return R.ok(webCountVos);
    }





}
